package com.ikapp.jetpackcomposeuidemo.weiget

import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsFocusedAsState
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ComposeCompilerApi
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.ikapp.jetpackcomposeuidemo.R

/**
 *  ANDROID STUDIO - VERSION 2022
 *  createTime: 2023/11/17 22:40
 *  Author: Ikun
 *  email: jikunwei41@gmail.com
 **/

// Test
@Composable
@Preview
fun TestShow() {
    ButtonTest()
}

// 创建 Data class 来记录不同状态下按钮的样式
data class ButtonState(var text: String, var textColor: Color, var buttonColor: Color)


/**
 * Button 按钮
 */
@Composable
fun ButtonTest(modifier: Modifier = Modifier) {
    // 获取按钮的状态
    val interactionState = remember {
        MutableInteractionSource()
    }

    // 使用 Kotlin 的解构方法
    val (text, textColor, buttonColor) = when {
        interactionState.collectIsFocusedAsState().value -> ButtonState(
            "Tom",
            Color.Red,
            Color.Black
        )

        else -> ButtonState("Ikun", Color.White, Color.Red)
    }

    Button(
        onClick = { /*TODO*/ },
        interactionSource = interactionState,
        elevation = null,
        shape = RoundedCornerShape(50.dp),
        modifier = modifier
            .width(IntrinsicSize.Min)
            .height(IntrinsicSize.Min)
    )
    {
        Text(text = text, color = textColor)
    }
}





















